package security.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import security.entity.UserDto;

import java.util.List;

@Component
public class UserDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public UserDto selectOne(String username){
        String sql = "select username,password from user where username=?";
        List<UserDto> userDtos = jdbcTemplate.query(sql, new Object[]{username}, new BeanPropertyRowMapper<UserDto>(UserDto.class));
        if (userDtos == null || userDtos.size() == 0){
            return null;
        }
        return userDtos.get(0);
    }
}
